Ext.namespace("Microtraining.Admin.Notice");
Mt = Microtraining.Admin;
Mt.Notice = {
    /**
     * 全局配置
     */
    Config: {
        /**
         *分页:每页显示记录数
         */
        PageSize: 15,
        /**
         *显示配置
         */
        View: {
            /**
             * 显示通知的视图相对通知列表Grid的位置
             * 1:上方,2:下方,3:左侧,4:右侧,
             */
            Direction: 2,
            /**
             *是否显示。
             */
            IsShow: 0,
            /**
             * 是否固定显示通知信息页(或者打开新窗口)
             */
            IsFix: 0
        },
        /**
         * 在线编辑器类型。
         * 1:CkEditor,2:KindEditor,3:xhEditor,4:UEditor
         * 配合Action的变量配置$online_editor
         */
        OnlineEditor: 4
    },
    /**
     * Cookie设置
     */
    Cookie: new Ext.state.CookieProvider(),
    /**
     * 初始化
     */
    Init: function() {
        if (Mt.Notice.Cookie.get('View.Direction')) {
            Mt.Notice.Config.View.Direction = Mt.Notice.Cookie.get('View.Direction');
        }
        if (Mt.Notice.Cookie.get('View.IsFix') != null) {
            Mt.Notice.Config.View.IsFix = Mt.Notice.Cookie.get('View.IsFix');
        }
        if (Ext.util.Cookies.get('OnlineEditor') != null) {
            Mt.Notice.Config.OnlineEditor = parseInt(Ext.util.Cookies.get('OnlineEditor'));
        }

    }
};
/**
 * Model:数据模型
 */
Mt.Notice.Store = {
    /**
     * 通知
     */

    comNtypeStore: new Ext.data.SimpleStore({
        fields: ['value', 'text'],
        data: [['1', '提醒学员关注'], ['2', '新课程上线通知'], ['3', '面授培训通知'], ['4', '课程到期通知'], ['5', '下载资料通知'], ['6', '问卷调查']]
    }),
    noticeStore: new Ext.data.Store({
        reader: new Ext.data.JsonReader({
            totalProperty: 'totalCount',
            successProperty: 'success',
            root: 'data', remoteSort: true,
            fields: [
                {name: 'notice_id', type: 'int'},
                {name: 'ntypeShow', type: 'string'},
                {name: 'ntype', type: 'string'},
                {name: 'notice_title', type: 'string'},
                {name: 'admin_name', type: 'string'},
                {name: 'content', type: 'string'},
                {name: 'contentShow', type: 'string'},
                {name: 'lesson_id', type: 'int'},
                {name: 'lesson_name', type: 'string'},
                {name: 'filename', type: 'string'},
                {name: 'filepath', type: 'string'},
                {name: 'toall', type: 'string'},
                {name: 'memberStr', type: 'string'}
            ]}
        ),
        writer: new Ext.data.JsonWriter({
            encode: false
        }),
        listeners: {
            beforeload: function(store, options) {
                if (Ext.isReady) {
                    if (!options.params.limit)
                        options.params.limit = Mt.Notice.Config.PageSize;
                    Ext.apply(options.params, Mt.Notice.View.Running.noticeGrid.filter);//保证分页也将查询条件带上
                }
            }
        }
    }),
    /**
     * 企业课程
     */
    lessonStoreForCombo: new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'home/admin/src/httpdata/lesson.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'lessons',
            autoLoad: true,
            totalProperty: 'totalCount',
            idProperty: 'lesson_id'
        }, [
            {name: 'lesson_id', mapping: 'lesson_id'},
            {name: 'lesson_name', mapping: 'lesson_name'}
        ])
    }),
    /**
     * 通知已读会员
     */
    mnoticeStore: new Ext.data.Store({
        reader: new Ext.data.JsonReader({
            totalProperty: 'totalCount',
            successProperty: 'success',
            root: 'data', remoteSort: true,
            fields: [
                {name: 'username', type: 'string'},
                {name: 'realname', type: 'string'},
                {name: 'department_name', type: 'string'},
                {name: 'position_name', type: 'string'},
                {name: 'area_name', type: 'string'}
            ]}
        ),
        writer: new Ext.data.JsonWriter({
            encode: false
        }),
        listeners: {
            beforeload: function(store, options) {
                if (Ext.isReady) {
                    if (!options.params.limit)
                        options.params.limit = Mt.Notice.Config.PageSize;
                    Ext.apply(options.params, Mt.Notice.View.Running.mnoticeGrid.filter);//保证分页也将查询条件带上
                }
            }
        }
    }),
    /**
     * 会员
     */
    selectMemberStore: new Ext.data.Store({
        reader: new Ext.data.JsonReader({
            totalProperty: 'totalCount',
            successProperty: 'success',
            root: 'data', remoteSort: true,
            fields: [
                {name: 'member_id', type: 'int'},
                {name: 'company_id', type: 'int'},
                {name: 'company_name', type: 'string'},
                {name: 'department_id', type: 'int'},
                {name: 'department_name', type: 'string'},
                {name: 'position_id', type: 'int'},
                {name: 'position_name', type: 'string'},
                {name: 'area_id', type: 'int'},
                {name: 'area_name', type: 'string'},
                {name: 'username', type: 'string'},
                {name: 'password', type: 'string'},
                {name: 'realname', type: 'string'},
                {name: 'code', type: 'string'},
                {name: 'tel', type: 'string'},
                {name: 'email', type: 'string'},
                {name: 'qq', type: 'string'},
                {name: 'weixin', type: 'string'},
                {name: 'icon_image', type: 'string'},
                {name: 'point', type: 'float'},
                {name: 'lessonStr', type: 'string'},
                {name: 'noticeStr', type: 'string'},
                {name: 'subjectStr', type: 'string'},
                {name: 'testStr', type: 'string'}
            ]}
        ),
        writer: new Ext.data.JsonWriter({
            encode: false
        }),
        listeners: {
            beforeload: function(store, options) {
                if (Ext.isReady) {
                    Ext.apply(options.params, Mt.Notice.View.Running.selectMemberWindow.memberGrid.filter);//保证分页也将查询条件带上
                }
            },
            load: function(records, options) {
                if (records && records.data && records.data.items) {
                    var selData = Mt.Notice.View.Running.selectMemberWindow.selData;//选中的会员
                    var data = records.data.items;
                    //把已经推荐的会员选中
                    var sm = Mt.Notice.View.Running.selectMemberWindow.memberGrid.sm;
                    var rows = Mt.Notice.View.Running.selectMemberWindow.memberGrid.getView().getRows();
                    for (var i = 0; i < rows.length; i++) {
                        if (selData[data[i]['data'].member_id]) {
                            sm.selectRow(i, true);
                        }
                    }
                }
            }
        }
    }),
    /**
     * 企业
     */
    companyStoreForCombo: new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'home/admin/src/httpdata/company.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'companys',
            autoLoad: true,
            totalProperty: 'totalCount',
            idProperty: 'company_id'
        }, [
            {name: 'company_id', mapping: 'company_id'},
            {name: 'company_name', mapping: 'company_name'}
        ])
    }),
    /**
     * 部门
     */
    departmentStoreForCombo: new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'home/admin/src/httpdata/department.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'departments',
            autoLoad: true,
            totalProperty: 'totalCount',
            idProperty: 'department_id'
        }, [
            {name: 'department_id', mapping: 'department_id'},
            {name: 'department_name', mapping: 'department_name'}
        ])
    }),
    /**
     * 职位
     */
    positionStoreForCombo: new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'home/admin/src/httpdata/position.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'positions',
            autoLoad: true,
            totalProperty: 'totalCount',
            idProperty: 'position_id'
        }, [
            {name: 'position_id', mapping: 'position_id'},
            {name: 'position_name', mapping: 'position_name'}
        ])
    }),
    /**
     * 地区
     */
    areaStoreForCombo: new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'home/admin/src/httpdata/area.php'
        }),
        reader: new Ext.data.JsonReader({
            root: 'areas',
            autoLoad: true,
            totalProperty: 'totalCount',
            idProperty: 'area_id'
        }, [
            {name: 'area_id', mapping: 'area_id'},
            {name: 'area_name', mapping: 'area_name'}
        ])
    })
};
/**
 * View:通知显示组件
 */
Mt.Notice.View = {
    /**
     * 编辑窗口：新建或者修改通知
     */
    EditWindow: Ext.extend(Ext.Window, {
        constructor: function(config) {
            config = Ext.apply({
                /**
                 * 自定义类型:保存类型
                 * 0:保存窗口,1:修改窗口
                 */
                savetype: 0,
                closeAction: "hide",
                constrainHeader: true, maximizable: true, collapsible: true,
                width: 450, height: 550, minWidth: 400, minHeight: 450,
                layout: 'fit', plain: true, buttonAlign: 'center',
                defaults: {
                    autoScroll: true
                },
                listeners: {
                    beforehide: function() {
                        this.editForm.form.getEl().dom.reset();
                    },
                    afterrender: function() {
                        switch (Mt.Notice.Config.OnlineEditor)
                        {
                            case 1:
                                ckeditor_replace_content();
                                break
                            case 2:
                                Mt.Notice.View.EditWindow.KindEditor_content = KindEditor.create('textarea[name="content"]', {width: '98%', minHeith: '350px', filterMode: true});
                                break
                            case 3:
                                pageInit_content();
                                break
                            default:
                                this.editForm.content.setWidth("98%");
                                pageInit_ue_content();
                        }
                    }
                },
                items: [
                    new Ext.form.FormPanel({
                        ref: 'editForm', layout: 'form', fileUpload: true,
                        labelWidth: 100, labelAlign: "center",
                        bodyStyle: 'padding:5px 5px 0', align: "center",
                        api: {},
                        defaults: {
                            xtype: 'textfield', anchor: '98%'
                        },
                        items: [
                            {xtype: 'hidden', name: 'notice_id', ref: '../notice_id'},
                            {xtype: 'hidden', name: 'ntype', ref: '../ntype'},
                            {fieldLabel: '通知标题', name: 'notice_title'},
                            {fieldLabel: '通知内容', name: 'content', xtype: 'textarea', id: 'content', ref: 'content'},
                            {xtype: 'hidden', name: 'lesson_id', ref: '../lesson_id'},
                            {
                                fieldLabel: '课程', xtype: 'combo', name: 'lesson_name', ref: '../lesson_name',
                                store: Mt.Notice.Store.lessonStoreForCombo, emptyText: '请选择课程', itemSelector: 'div.search-item',
                                loadingText: '查询中...', width: 570, pageSize: Mt.Notice.Config.PageSize,
                                displayField: 'lesson_name', grid: this,
                                mode: 'remote', editable: true, minChars: 1, autoSelect: true, typeAhead: false,
                                forceSelection: true, triggerAction: 'all', resizable: false, selectOnFocus: true,
                                tpl: new Ext.XTemplate(
                                        '<tpl for="."><div class="search-item">',
                                        '<h3>{lesson_name}</h3>',
                                        '</div></tpl>'
                                        ),
                                listeners: {
                                    'beforequery': function(event) {
                                        delete event.combo.lastQuery;
                                    }
                                },
                                onSelect: function(record, index) {
                                    if (this.fireEvent('beforeselect', this, record, index) !== false) {
                                        this.grid.lesson_id.setValue(record.data.lesson_id);
                                        this.grid.lesson_name.setValue(record.data.lesson_name);
                                        this.collapse();
                                    }
                                }
                            },
                            {xtype: 'hidden', name: 'filename', ref: '../filename'},
                            {xtype: 'hidden', name: 'filepath', ref: '../filepath'},
                            {fieldLabel: '文件路径', name: 'filepathUpload', ref: '../filepathUpload', xtype: 'fileuploadfield',
                                emptyText: '请上传文件路径文件', buttonText: '', accept: '*/*', buttonCfg: {iconCls: 'upload-icon'}},
                            {fieldLabel: '全部发送', hiddenName: 'toall'
                                , xtype: 'combo', ref: '../toall', mode: 'local', triggerAction: 'all',
                                lazyRender: true, editable: false, allowBlank: false, valueNotFoundText: '否',
                                store: new Ext.data.SimpleStore({
                                    fields: ['value', 'text'],
                                    data: [['0', '否'], ['1', '是']]
                                }), emptyText: '请选择全部发送',
                                valueField: 'value', displayField: 'text'
                            }
                        ]
                    })
                ],
                buttons: [{
                        text: "", ref: "../saveBtn", scope: this,
                        handler: function() {
                            switch (Mt.Notice.Config.OnlineEditor)
                            {
                                case 1:
                                    if (CKEDITOR.instances.content)
                                        this.editForm.content.setValue(CKEDITOR.instances.content.getData());
                                    break
                                case 2:
                                    if (Mt.Notice.View.EditWindow.KindEditor_content)
                                        this.editForm.content.setValue(Mt.Notice.View.EditWindow.KindEditor_content.html());
                                    break
                                case 3:
                                    if (xhEditor_content)
                                        this.editForm.content.setValue(xhEditor_content.getSource());
                                    break
                                default:
                                    if (ue_content)
                                        this.editForm.content.setValue(ue_content.getContent());
                            }

                            if (!this.editForm.getForm().isValid()) {
                                return;
                            }
                            editWindow = this;
                            if (this.savetype == 0) {
                                this.editForm.api.submit = ExtServiceNotice.save;
                                this.editForm.getForm().submit({
                                    success: function(form, action) {
                                        Ext.Msg.alert("提示", "保存成功！");
                                        Mt.Notice.View.Running.noticeGrid.doSelectNotice();
                                        form.reset();
                                        editWindow.hide();
                                    },
                                    failure: function(form, response) {
                                        Ext.Msg.show({title: '提示', width: 350, buttons: {yes: '确定'}, msg: response.result.msg});
                                    }
                                });
                            } else {
                                this.editForm.api.submit = ExtServiceNotice.update;
                                this.editForm.getForm().submit({
                                    success: function(form, action) {
                                        Mt.Notice.View.Running.noticeGrid.store.reload();
                                        Ext.Msg.show({title: '提示', msg: '修改成功！', buttons: {yes: '确定'}, fn: function() {
                                                Mt.Notice.View.Running.noticeGrid.bottomToolbar.doRefresh();
                                            }});
                                        form.reset();
                                        editWindow.hide();
                                    },
                                    failure: function(form, response) {
                                        Ext.Msg.show({title: '提示', width: 350, buttons: {yes: '确定'}, msg: response.result.msg});
                                    }
                                });
                            }
                        }
                    }, {
                        text: "取 消", scope: this,
                        handler: function() {
                            this.hide();
                        }
                    }, {
                        text: "重 置", ref: '../resetBtn', scope: this,
                        handler: function() {
                            this.editForm.form.loadRecord(Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected());
                            this.filepathUpload.setValue(this.filename.getValue());
                            switch (Mt.Notice.Config.OnlineEditor)
                            {
                                case 1:
                                    if (CKEDITOR.instances.content)
                                        CKEDITOR.instances.content.setData(Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected().data.content);
                                    break
                                case 2:
                                    if (Mt.Notice.View.EditWindow.KindEditor_content)
                                        Mt.Notice.View.EditWindow.KindEditor_content.html(Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected().data.content);
                                    break
                                case 3:
                                    if (xhEditor_content)
                                        xhEditor_content.setSource(Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected().data.content);
                                    break
                                default:
                                    if (ue_content)
                                        ue_content.setContent(Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected().data.content);
                            }
                        }
                    }]
            }, config);
            Mt.Notice.View.EditWindow.superclass.constructor.call(this, config);
        }
    }),
    /**
     * 显示通知详情
     */
    NoticeView: {
        /**
         * Tab页：容器包含显示与通知所有相关的信息
         */
        Tabs: Ext.extend(Ext.TabPanel, {
            constructor: function(config) {
                config = Ext.apply({
                    region: 'south', collapseMode: 'mini', split: true,
                    activeTab: 1, tabPosition: "bottom", resizeTabs: true,
                    header: false, enableTabScroll: true, tabWidth: 'auto', margins: '0 3 3 0',
                    defaults: {
                        autoScroll: true,
                        layout: 'fit'
                    },
                    listeners: {
                        beforetabchange: function(tabs, newtab, currentTab) {
                            if (tabs.tabFix == newtab) {
                                if (Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected() == null) {
                                    Ext.Msg.alert('提示', '请先选择通知！');
                                    return false;
                                }
                                Mt.Notice.Config.View.IsShow = 1;
                                Mt.Notice.View.Running.noticeGrid.showNotice();
                                Mt.Notice.View.Running.noticeGrid.tvpView.menu.mBind.setChecked(false);
                                return false;
                            }
                        }
                    },
                    items: [
                        {title: '+', tabTip: '取消固定', ref: 'tabFix', iconCls: 'icon-fix'}
                    ]
                }, config);
                Mt.Notice.View.NoticeView.Tabs.superclass.constructor.call(this, config);
                Mt.Notice.View.Running.mnoticeGrid = new Mt.Notice.View.MnoticeView.Grid();
                this.onAddItems();
            },
            /**
             * 根据布局调整Tabs的宽度或者高度以及折叠
             */
            enableCollapse: function() {
                if ((Mt.Notice.Config.View.Direction == 1) || (Mt.Notice.Config.View.Direction == 2)) {
                    this.width = Ext.getBody().getViewSize().width;
                    this.height = Ext.getBody().getViewSize().height / 2;
                } else {
                    this.width = Ext.getBody().getViewSize().width / 2;
                    this.height = Ext.getBody().getViewSize().height;
                }
                this.ownerCt.setSize(this.width, this.height);
                if (this.ownerCt.collapsed)
                    this.ownerCt.expand();
                this.ownerCt.collapsed = false;
            },
            onAddItems: function() {
                this.add(
                        {title: '基本信息', ref: 'tabNoticeDetail', iconCls: 'tabs',
                            tpl: [
                                '<table class="viewdoblock">',
                                '  <tr class="entry"><td class="head">通知类型</td><td class="content">{ntypeShow}</td></tr>',
                                '  <tr class="entry"><td class="head">通知标题</td><td class="content">{notice_title}</td></tr>',
                                '  <tr class="entry"><td class="head">通知内容</td><td class="content">{contentShow}</td></tr>',
                                '  <tr class="entry"><td class="head">课程</td><td class="content">{lesson_name}</td></tr>',
                                '  <tr class="entry"><td class="head">文件名</td><td class="content">{filename}</td></tr>',
                                '  <tr class="entry"><td class="head">文件路径</td><td class="content">{filepath}</td></tr>',
                                '  <tr class="entry"><td class="head">文件</td><td class="content"><tpl if="filepath"><a href="upload/images/{filepath}" target="_blank"><img src="upload/images/{filepath}" /></a></tpl></td></tr>',
                                '  <tr class="entry"><td class="head">全部发送</td><td class="content"><tpl if="toall == true">是</tpl><tpl if="toall == false">否</tpl></td></tr>',
                                '  <tr class="entry"><td class="head">发送人</td><td class="content">{admin_name}</td></tr>',
                                '</table>'
                            ]}
                );
                this.add(
                        {title: '已阅读通知会员', iconCls: 'tabs', tabWidth: 150,
                            items: [Mt.Notice.View.Running.mnoticeGrid]
                        }
                );
            }
        }),
        /**
         * 窗口:显示通知信息
         */
        Window: Ext.extend(Ext.Window, {
            constructor: function(config) {
                config = Ext.apply({
                    title: "查看通知", constrainHeader: true, maximizable: true, minimizable: true,
                    width: 705, height: 500, minWidth: 450, minHeight: 400,
                    layout: 'fit', resizable: true, plain: true, bodyStyle: 'padding:5px;',
                    closeAction: "hide",
                    items: [new Mt.Notice.View.NoticeView.Tabs({ref: 'winTabs', tabPosition: 'top'})],
                    listeners: {
                        minimize: function(w) {
                            w.hide();
                            Mt.Notice.Config.View.IsShow = 0;
                            Mt.Notice.View.Running.noticeGrid.tvpView.menu.mBind.setChecked(true);
                        },
                        hide: function(w) {
                            Mt.Notice.View.Running.noticeGrid.tvpView.toggle(false);
                        }
                    }/*,
                     buttons: [{
                     text: '新增通知',scope:this,
                     handler : function() {this.hide();Mt.Notice.View.Running.noticeGrid.addNotice();}
                     },{
                     text: '修改通知',scope:this,
                     handler : function() {this.hide();Mt.Notice.View.Running.noticeGrid.updateNotice();}
                     }]*/
                }, config);
                Mt.Notice.View.NoticeView.Window.superclass.constructor.call(this, config);
            }
        })
    },
    /**
     * 视图：会员
     */
    MemberView: {
        SelectMemberWindow: Ext.extend(Ext.Window, {
            constructor: function(config) {
                config = Ext.apply({
                    selData: null, //选中的会员
                    oldData: null, //已关联的会员
                    title: "选择会员", updateData: null, closeAction: "hide", constrainHeader: true, maximizable: true, collapsible: true,
                    width: 720, minWidth: 720, height: 560, minHeight: 450, layout: 'fit', plain: true, buttonAlign: 'center',
                    defaults: {autoScroll: true, },
                    listeners: {
                        beforehide: this.doHide
                    },
                    items: [new Mt.Notice.View.MemberView.MemberGrid({ref: "memberGrid"})],
                    buttons: [{
                            text: "确定", ref: "../saveBtn", scope: this,
                            handler: function() {
                                var selData = this.selData;
                                var oldData = this.oldData;
                                //通知标识
                                var notice_id = Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected().data.notice_id;
                                var toall = Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected().data.toall;
                                if (toall != 0) {
                                    Ext.Msg.alert('提示', "该通知为群发，不能在选择会员");
                                    return false;
                                }
                                var condition = {'selData': selData, "oldData": oldData, "notice_id": notice_id};
                                Ext.Msg.show({
                                    title: '请等待', msg: '操作进行中，请稍后...',
                                    animEl: 'loading', icon: Ext.Msg.WARNING,
                                    closable: true, progress: true, progressText: '', width: 300
                                });
                                ExtServiceNotice.updateNoticeMember(condition, function(provider, response) {
                                    if (response.result.success == true) {
                                        var msg = "操作成功！";
                                        if (response.result.del) {
                                            msg += "<font color=red>取消</font>了<font color=red>" + response.result.del + "</font>个关联会员,";
                                        }
                                        if (response.result.add) {
                                            msg += "<font color=green>添加</font>了<font color=green>" + response.result.add + "</font>个关联会员";
                                        }
                                        Ext.Msg.alert('提示', msg);
                                    } else {
                                        Mt.Notice.Store.selectMemberStore.removeAll();
                                        Ext.Msg.alert('提示', '操作失败！');
                                    }
                                    Mt.Notice.View.Running.selectMemberWindow.hideWindow();
                                    Mt.Notice.View.Running.noticeGrid.doSelectNotice();
                                });
                            }
                        }, {
                            text: "取 消", scope: this,
                            handler: function() {
                                this.hide();
                            }
                        }]
                }, config);
                Mt.Notice.View.MemberView.SelectMemberWindow.superclass.constructor.call(this, config);
            },
            /**
             * 根据选择的会员,改变标题
             */
            changeTitle: function() {
                var title = "选择 会员";
                var selData = this.selData;
                var count = this.objElCount(selData);
                if (count) {
                    title += "（已经选择了<font color=green>" + count + "</font>件会员）";
                } else {
                    title += "（尚未选择任何会员）";
                }
                this.setTitle(title);
            },
            /**
             * 判断自定义对象元素个数
             */
            objElCount: function(obj) {
                var count = 0;
                for (var n in obj) {
                    count++
                }
                return count;
            },
            /**
             * 确认取消图片处理
             * con:选择窗口
             */
            doHide: function(con) {
                //window初始化时会调用,此时con为null
                if (con) {
                    Ext.MessageBox.show({
                        title: '提示', msg: '确定要取消么?<br /><font color=red>(所做操作将不会保存!)</font>', buttons: Ext.MessageBox.YESNO, icon: Ext.MessageBox.QUESTION,
                        params: {con: con},
                        fn: function(btn, text, opt) {
                            if (btn == 'yes') {
                                con.hideWindow();
                            }
                        }
                    });
                    return false;
                }
            },
            /**
             * 隐藏窗口
             */
            hideWindow: function() {
                //移除beforehide事件，为了防止hide时进入死循环
                this.un('beforehide', this.doHide);
                this.hide();
                this.addListener('beforehide', this.doHide);
            }
        }),
        MemberGrid: Ext.extend(Ext.grid.GridPanel, {
            constructor: function(config) {
                config = Ext.apply({
                    /**
                     * 查询条件
                     */
                    filter: null, notice_id: null, region: 'center', store: Mt.Notice.Store.selectMemberStore, sm: this.sm,
                    trackMouseOver: true, enableColumnMove: true, columnLines: true, loadMask: true, stripeRows: true, headerAsText: false,
                    loadMask : {msg: '加载数据中，请稍候...'},
                    defaults: {autoScroll: true},
                    cm: new Ext.grid.ColumnModel({
                        defaults: {width: 120, sortable: true},
                        columns: [
                            this.sm,
                            {header: '标识', dataIndex: 'member_id', hidden: true},
                            {header: '公司', dataIndex: 'company_name'},
                            {header: '部门', dataIndex: 'department_name'},
                            {header: '职位', dataIndex: 'position_name'},
                            {header: '地区', dataIndex: 'area_name'},
                            {header: '用户名', dataIndex: 'username'},
                            {header: '密码', dataIndex: 'password'},
                            {header: '姓名', dataIndex: 'realname'},
                            {header: '员工号', dataIndex: 'code'},
                            {header: '电话', dataIndex: 'tel'},
                            {header: 'email', dataIndex: 'email'},
                            {header: 'qq', dataIndex: 'qq'},
                            {header: '微信', dataIndex: 'weixin'},
                            {header: '积分', dataIndex: 'point'}
                        ]
                    }),
                    tbar: {
                        xtype: 'container', layout: 'anchor',
                        height: 27, style: 'font-size:14px',
                        defaults: {
                            height: 27, anchor: '100%'
                        },
                        items: [
                            new Ext.Toolbar({
                                enableOverflow: true, width: 80, ref: 'menus',
                                defaults: {
                                    xtype: 'textfield',
                                    listeners: {
                                        specialkey: function(field, e) {
                                            if (e.getKey() == Ext.EventObject.ENTER)
                                                this.ownerCt.ownerCt.ownerCt.doSelectMember();
                                        }
                                    }
                                },
                                items: [
                                    {text: '全部', ref: '../../isSelect', xtype: 'tbsplit', iconCls: 'icon-view', enableToggle: true,
                                        toggleHandler: function(item, checked) {
                                            if (checked == true) {
                                                Mt.Notice.View.Running.selectMemberWindow.memberGrid.topToolbar.menus.select.setChecked(true);
                                            } else {
                                                Mt.Notice.View.Running.selectMemberWindow.memberGrid.topToolbar.menus.all.setChecked(true);
                                            }
                                        },
                                        menu: {
                                            items: [
                                                {text: '全部', checked: true, group: 'isSelect', ref: '../../all',
                                                    checkHandler: function(item, checked) {
                                                        if (checked) {
                                                            Mt.Notice.View.Running.selectMemberWindow.memberGrid.isSelect.setText(item.text);
                                                            Mt.Notice.View.Running.selectMemberWindow.memberGrid.filter.selectType = 0;
                                                        }
                                                        Mt.Notice.View.Running.selectMemberWindow.memberGrid.doSelectMember();
                                                    }
                                                },
                                                {text: '未选择', checked: false, group: 'isSelect', ref: '../../unselect',
                                                    checkHandler: function(item, checked) {
                                                        if (checked) {
                                                            Mt.Notice.View.Running.selectMemberWindow.memberGrid.isSelect.setText(item.text);
                                                            Mt.Notice.View.Running.selectMemberWindow.memberGrid.filter.selectType = 2;
                                                        }
                                                        Mt.Notice.View.Running.selectMemberWindow.memberGrid.doSelectMember();
                                                    }
                                                },
                                                {text: '已选择', checked: false, group: 'isSelect', ref: '../../select',
                                                    checkHandler: function(item, checked) {
                                                        if (checked) {
                                                            Mt.Notice.View.Running.selectMemberWindow.memberGrid.isSelect.setText(item.text);
                                                            Mt.Notice.View.Running.selectMemberWindow.memberGrid.filter.selectType = 1;
                                                        }
                                                        Mt.Notice.View.Running.selectMemberWindow.memberGrid.doSelectMember();
                                                    }
                                                }
                                            ]
                                        }
                                    },
                                    '地区', '&nbsp;&nbsp;', {ref: '../area_id', xtype: 'combo',
                                        store: Mt.Notice.Store.areaStoreForCombo, hiddenName: 'area_id',
                                        emptyText: '请选择地区', itemSelector: 'div.search-item',
                                        loadingText: '查询中...', width: 280, pageSize: Mt.Notice.Config.PageSize,
                                        displayField: 'area_name', valueField: 'area_id',
                                        mode: 'remote', editable: true, minChars: 1, autoSelect: true, typeAhead: false,
                                        forceSelection: true, triggerAction: 'all', resizable: true, selectOnFocus: true,
                                        tpl: new Ext.XTemplate(
                                                '<tpl for="."><div class="search-item">',
                                                '<h3>{area_name}</h3>',
                                                '</div></tpl>'
                                                )
                                    }, '&nbsp;&nbsp;',
                                    '部门', '&nbsp;&nbsp;', {ref: '../mdepartment_id', xtype: 'combo',
                                        store: Mt.Notice.Store.departmentStoreForCombo, hiddenName: 'department_id',
                                        emptyText: '请选择部门', itemSelector: 'div.search-item',
                                        loadingText: '查询中...', width: 280, pageSize: Mt.Notice.Config.PageSize,
                                        displayField: 'department_name', valueField: 'department_id',
                                        mode: 'remote', editable: true, minChars: 1, autoSelect: true, typeAhead: false,
                                        forceSelection: true, triggerAction: 'all', resizable: true, selectOnFocus: true,
                                        tpl: new Ext.XTemplate(
                                                '<tpl for="."><div class="search-item">',
                                                '<h3>{department_name}</h3>',
                                                '</div></tpl>'
                                                )
                                    }, '&nbsp;&nbsp;',
                                    '职位', '&nbsp;&nbsp;', {ref: '../mposition_id', xtype: 'combo',
                                        store: Mt.Notice.Store.positionStoreForCombo, hiddenName: 'position_id',
                                        emptyText: '请选择职位', itemSelector: 'div.search-item',
                                        loadingText: '查询中...', width: 280, pageSize: Mt.Notice.Config.PageSize,
                                        displayField: 'position_name', valueField: 'position_id',
                                        mode: 'remote', editable: true, minChars: 1, autoSelect: true, typeAhead: false,
                                        forceSelection: true, triggerAction: 'all', resizable: true, selectOnFocus: true,
                                        tpl: new Ext.XTemplate(
                                                '<tpl for="."><div class="search-item">',
                                                '<h3>{position_name}</h3>',
                                                '</div></tpl>'
                                                )
                                    }, '&nbsp;&nbsp;',
                                    '用户名', '&nbsp;&nbsp;', {ref: '../musername'}, '&nbsp;&nbsp;',
                                    {
                                        xtype: 'button', text: '查询', scope: this,
                                        handler: function() {
                                            this.doSelectMember();
                                        }
                                    },
                                    {
                                        xtype: 'button', text: '重置', scope: this,
                                        handler: function() {
                                            this.topToolbar.area_id.setValue("");
                                            this.topToolbar.mdepartment_id.setValue("");
                                            this.topToolbar.mposition_id.setValue("");
                                            this.topToolbar.musername.setValue("");
                                            this.filter = {};
                                            this.doSelectMember();
                                        }
                                    }
                                ]
                            })
                        ]
                    },
                    bbar: new Ext.PagingToolbar({
                        pageSize: Mt.Notice.Config.PageSize,
                        store: Mt.Notice.Store.selectMemberStore,
                        scope: this, autoShow: true, displayInfo: true,
                        displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',
                        emptyMsg: "无显示数据",
                        items: [
                            {xtype: 'label', text: '每页显示'},
                            {xtype: 'numberfield', value: Mt.Notice.Config.PageSize, minValue: 1, width: 35,
                                style: 'text-align:center', allowBlank: false,
                                listeners:
                                        {
                                            change: function(Field, newValue, oldValue) {
                                                var num = parseInt(newValue);
                                                if (isNaN(num) || !num || num < 1)
                                                {
                                                    num = Mt.Notice.Config.PageSize;
                                                    Field.setValue(num);
                                                }
                                                Mt.Notice.Config.PageSize = num;
                                                this.ownerCt.ownerCt.doSelectMember();
                                            },
                                            specialKey: function(field, e) {
                                                if (e.getKey() == Ext.EventObject.ENTER) {
                                                    var num = parseInt(field.getValue());
                                                    if (isNaN(num) || !num || num < 1)
                                                    {
                                                        num = Mt.Notice.Config.PageSize;
                                                    }
                                                    Mt.Notice.Config.PageSize = num;
                                                    this.ownerCt.ownerCt.doSelectMember();
                                                }
                                            }
                                        }
                            },
                            {xtype: 'label', text: '个'}
                        ]
                    })
                }, config);
                //初始化显示会员列表
                //this.doSelectMember();
                Mt.Notice.Store.selectMemberStore.proxy = new Ext.data.DirectProxy({
                    api: {read: ExtServiceNotice.queryPageNoticeMember}
                });
                Mt.Notice.View.MemberView.MemberGrid.superclass.constructor.call(this, config);
            },
            /**
             * SelectionModel
             */
            sm: new Ext.grid.CheckboxSelectionModel({
                listeners: {
                    selectionchange: function(sm) {
                        Mt.Notice.View.Running.selectMemberWindow.changeTitle();
                        Mt.Notice.View.Running.selectMemberWindow.memberGrid.changeFilter();
                    },
                    rowselect: function(sm, rowIndex, record) {
                        var selMemberWin = Mt.Notice.View.Running.selectMemberWindow;
                        var selData = selMemberWin.selData;
                        var oldData = selMemberWin.oldData;
                        var member_id = record.data.member_id;
                        //添加该货品ID
                        selData[member_id] = true;
                        //判断是否是已关联的货品
                        if (oldData[member_id]) {
                            oldData[member_id].active = true;
                        }
                    },
                    rowdeselect: function(sm, rowIndex, record) {
                        var selMemberWin = Mt.Notice.View.Running.selectMemberWindow;
                        var selData = selMemberWin.selData;
                        var oldData = selMemberWin.oldData;
                        var member_id = record.data.member_id;
                        //删除该货品ID
                        delete selData[member_id];
                        //判断是否是已关联的货品
                        if (oldData[member_id]) {
                            oldData[member_id].active = false;
                        }
                    }
                }
            }),
            doSelectMember: function() {
                var tmp_selMember = this.filter.selMember;
                if (this.topToolbar) {
                    var notice_id = this.notice_id;
                    if (!this.filter.selectType)
                        this.filter.selectType = 0;
                    var area_id = this.topToolbar.area_id.getValue();
                    var mdepartment_id = this.topToolbar.mdepartment_id.getValue();
                    var mposition_id = this.topToolbar.mposition_id.getValue();
                    var musername = this.topToolbar.musername.getValue();
                    this.filter = {'area_id': area_id, 'department_id': mdepartment_id, 'position_id': mposition_id, 'username': musername, 'notice_id': notice_id, 'selectType': this.filter.selectType};
                }
                this.filter.selMember = tmp_selMember;
                var condition = {'start': 0, 'limit': Mt.Notice.Config.PageSize};
                Ext.apply(condition, this.filter);
                ExtServiceNotice.queryPageNoticeMember(condition, function(provider, response) {
                    if (response.result && response.result.data) {
                        var result = new Array();
                        result['data'] = response.result.data;
                        result['totalCount'] = response.result.totalCount;
                        Mt.Notice.Store.selectMemberStore.loadData(result);
                    } else {
                        Mt.Notice.Store.selectMemberStore.removeAll();
                        Ext.Msg.alert('提示', '无符合条件的会员！');
                    }
                });
            },
            /**
             * 修改查询条件
             */
            changeFilter: function() {
                var selData = Mt.Notice.View.Running.selectMemberWindow.selData;
                var selArr = new Array();
                for (var x in selData) {
                    selArr.push(x);
                }
                this.filter.selMember = selArr.join(",");
            }
        }),
    },
    /**
     * 视图：通知已读会员列表
     */
    MnoticeView: {
        /**
         *  当前创建的通知已读会员编辑窗口
         */
        edit_window: null,
        /**
         * 编辑窗口：新建或者修改通知已读会员
         */
        EditWindow: Ext.extend(Ext.Window, {
            constructor: function(config) {
                config = Ext.apply({
                    /**
                     * 自定义类型:保存类型
                     * 0:保存窗口,1:修改窗口
                     */
                    savetype: 0, closeAction: "hide", constrainHeader: true, maximizable: true, collapsible: true,
                    width: 450, height: 550, minWidth: 400, minHeight: 450,
                    layout: 'fit', plain: true, buttonAlign: 'center',
                    defaults: {autoScroll: true},
                    listeners: {
                        beforehide: function() {
                            this.editForm.form.getEl().dom.reset();
                        }
                    },
                    items: [
                        new Ext.form.FormPanel({
                            ref: 'editForm', layout: 'form',
                            labelWidth: 100, labelAlign: "center",
                            bodyStyle: 'padding:5px 5px 0', align: "center",
                            api: {},
                            defaults: {
                                xtype: 'textfield', anchor: '98%'
                            },
                            items: [
                                {xtype: 'hidden', name: 'mtest_id', ref: '../mtest_id'},
                                {xtype: 'hidden', name: 'company_id', ref: '../company_id'},
                                {
                                    fieldLabel: '企业', xtype: 'combo', name: 'company_name', ref: '../company_name',
                                    store: Mt.Notice.Store.companyStoreForCombo, emptyText: '请选择企业', itemSelector: 'div.search-item',
                                    loadingText: '查询中...', width: 570, pageSize: Mt.Notice.Config.PageSize,
                                    displayField: 'company_name', grid: this,
                                    mode: 'remote', editable: true, minChars: 1, autoSelect: true, typeAhead: false,
                                    forceSelection: true, triggerAction: 'all', resizable: false, selectOnFocus: true,
                                    tpl: new Ext.XTemplate(
                                            '<tpl for="."><div class="search-item">',
                                            '<h3>{company_name}</h3>',
                                            '</div></tpl>'
                                            ),
                                    listeners: {
                                        'beforequery': function(event) {
                                            delete event.combo.lastQuery;
                                        }
                                    },
                                    onSelect: function(record, index) {
                                        if (this.fireEvent('beforeselect', this, record, index) !== false) {
                                            this.grid.company_id.setValue(record.data.company_id);
                                            this.grid.company_name.setValue(record.data.company_name);
                                            this.collapse();
                                        }
                                    }
                                },
                                {xtype: 'hidden', name: 'member_id', ref: '../member_id'},
                                {
                                    fieldLabel: '会员', xtype: 'combo', name: 'username', ref: '../username',
                                    store: Mt.Notice.Store.memberStoreForCombo, emptyText: '请选择会员', itemSelector: 'div.search-item',
                                    loadingText: '查询中...', width: 570, pageSize: Mt.Notice.Config.PageSize,
                                    displayField: 'username', grid: this,
                                    mode: 'remote', editable: true, minChars: 1, autoSelect: true, typeAhead: false,
                                    forceSelection: true, triggerAction: 'all', resizable: false, selectOnFocus: true,
                                    tpl: new Ext.XTemplate(
                                            '<tpl for="."><div class="search-item">',
                                            '<h3>{username}</h3>',
                                            '</div></tpl>'
                                            ),
                                    listeners: {
                                        'beforequery': function(event) {
                                            delete event.combo.lastQuery;
                                        }
                                    },
                                    onSelect: function(record, index) {
                                        if (this.fireEvent('beforeselect', this, record, index) !== false) {
                                            this.grid.member_id.setValue(record.data.member_id);
                                            this.grid.username.setValue(record.data.username);
                                            this.collapse();
                                        }
                                    }
                                }
                            ]
                        })
                    ],
                    buttons: [{
                            text: "", ref: "../saveBtn", scope: this,
                            handler: function() {

                                if (!this.editForm.getForm().isValid()) {
                                    return;
                                }
                                editWindow = this;
                                if (this.savetype == 0) {
                                    this.editForm.api.submit = ExtServiceMnotice.save;
                                    this.editForm.getForm().submit({
                                        success: function(form, action) {
                                            Ext.Msg.alert("提示", "保存成功！");
                                            Mt.Notice.View.Running.mnoticeGrid.doSelectMnotice();
                                            form.reset();
                                            editWindow.hide();
                                        },
                                        failure: function(form, response) {
                                            Ext.Msg.show({title: '提示', width: 350, buttons: {yes: '确定'}, msg: response.result.msg});
                                        }
                                    });
                                } else {
                                    this.editForm.api.submit = ExtServiceMnotice.update;
                                    this.editForm.getForm().submit({
                                        success: function(form, action) {
                                            Ext.Msg.show({title: '提示', msg: '修改成功！', buttons: {yes: '确定'}, fn: function() {
                                                    Mt.Notice.View.Running.mnoticeGrid.bottomToolbar.doRefresh();
                                                }});
                                            form.reset();
                                            editWindow.hide();
                                        },
                                        failure: function(form, response) {
                                            Ext.Msg.show({title: '提示', width: 350, buttons: {yes: '确定'}, msg: response.result.msg});
                                        }
                                    });
                                }
                            }
                        }, {
                            text: "取 消", scope: this,
                            handler: function() {
                                this.hide();
                            }
                        }, {
                            text: "重 置", ref: '../resetBtn', scope: this,
                            handler: function() {
                                this.editForm.form.loadRecord(Mt.Notice.View.Running.mnoticeGrid.getSelectionModel().getSelected());

                            }
                        }]
                }, config);
                Mt.Notice.View.MnoticeView.EditWindow.superclass.constructor.call(this, config);
            }
        }),
        /**
         * 查询条件
         */
        filter: null,
        /**
         * 视图：通知已读会员列表
         */
        Grid: Ext.extend(Ext.grid.GridPanel, {
            constructor: function(config) {
                config = Ext.apply({
                    store: Mt.Notice.Store.mnoticeStore, sm: this.sm,
                    frame: true, trackMouseOver: true, enableColumnMove: true, columnLines: true,
                    loadMask: true, stripeRows: true, headerAsText: false,
                    defaults: {autoScroll: true},
                    cm: new Ext.grid.ColumnModel({
                        defaults: {
                            width: 120, sortable: true
                        },
                        columns: [
                            this.sm,
                            {header: '会员', dataIndex: 'username'},
                            {header: '姓名', dataIndex: 'realname'},
                            {header: '部门', dataIndex: 'department_name'},
                            {header: '职位', dataIndex: 'position_name'},
                            {header: '地区', dataIndex: 'area_name'}
                        ]
                    }),
                    tbar: {
                        xtype: 'container', layout: 'anchor',
                        height: 27, style: 'font-size:14px',
                        defaults: {
                            height: 27, anchor: '100%'
                        },
                        items: [
                            new Ext.Toolbar({
                                defaults: {
                                    scope: this
                                },
                                items: [
                                    {
                                        text: '反选', iconCls: 'icon-reverse',
                                        handler: function() {
                                            this.onReverseSelect();
                                        }
                                    }/*,'-',{
                                     text : '添加通知已读会员',iconCls : 'icon-add',
                                     handler : function() {
                                     this.addMnotice();
                                     }
                                     },'-',{
                                     text : '修改通知已读会员',ref: '../../btnUpdate',iconCls : 'icon-edit',disabled : true,
                                     handler : function() {
                                     this.updateMnotice();
                                     }
                                     },'-',{
                                     text : '删除通知已读会员', ref: '../../btnRemove',iconCls : 'icon-delete',disabled : true,
                                     handler : function() {
                                     this.deleteMnotice();
                                     }
                                     }*/, '-']}
                            )]
                    },
                    bbar: new Ext.PagingToolbar({
                        pageSize: Mt.Notice.Config.PageSize,
                        store: Mt.Notice.Store.mnoticeStore, scope: this, autoShow: true, displayInfo: true,
                        displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。', emptyMsg: "无显示数据",
                        items: [
                            {xtype: 'label', text: '每页显示'},
                            {xtype: 'numberfield', value: Mt.Notice.Config.PageSize, minValue: 1, width: 35, style: 'text-align:center', allowBlank: false,
                                listeners:
                                        {
                                            change: function(Field, newValue, oldValue) {
                                                var num = parseInt(newValue);
                                                if (isNaN(num) || !num || num < 1)
                                                {
                                                    num = Mt.Notice.Config.PageSize;
                                                    Field.setValue(num);
                                                }
                                                this.ownerCt.pageSize = num;
                                                Mt.Notice.Config.PageSize = num;
                                                this.ownerCt.ownerCt.doSelectMnotice();
                                            },
                                            specialKey: function(field, e) {
                                                if (e.getKey() == Ext.EventObject.ENTER) {
                                                    var num = parseInt(field.getValue());
                                                    if (isNaN(num) || !num || num < 1)
                                                        num = Mt.Notice.Config.PageSize;
                                                    this.ownerCt.pageSize = num;
                                                    Mt.Notice.Config.PageSize = num;
                                                    this.ownerCt.ownerCt.doSelectMnotice();
                                                }
                                            }
                                        }
                            }, {xtype: 'label', text: '个'}
                        ]
                    })
                }, config);
                /**
                 * 通知已读会员数据模型获取数据Direct调用
                 */
                Mt.Notice.Store.mnoticeStore.proxy = new Ext.data.DirectProxy({
                    api: {read: ExtServiceMnotice.queryPageMnotice}
                });
                Mt.Notice.View.MnoticeView.Grid.superclass.constructor.call(this, config);
            },
            /**
             * 行选择器
             */
            sm: new Ext.grid.CheckboxSelectionModel({
                listeners: {
                    selectionchange: function(sm) {
                        // 判断删除和更新按钮是否可以激活
                        this.grid.btnRemove.setDisabled(sm.getCount() < 1);
                        this.grid.btnUpdate.setDisabled(sm.getCount() != 1);
                    }
                }
            }),
            /**
             * 查询符合条件的通知已读会员
             */
            doSelectMnotice: function() {
                if (Mt.Notice.View.Running.noticeGrid && Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected()) {
                    var notice_id = Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected().data.notice_id;
                    var condition = {'notice_id': notice_id, 'start': 0, 'limit': Mt.Notice.Config.PageSize};
                    this.filter = {'notice_id': notice_id};
                    ExtServiceMnotice.queryPageMnotice(condition, function(provider, response) {
                        if (response.result) {
                            if (response.result.data) {
                                var result = new Array();
                                result['data'] = response.result.data;
                                result['totalCount'] = response.result.totalCount;
                                Mt.Notice.Store.mnoticeStore.loadData(result);
                            } else {
                                Mt.Notice.Store.mnoticeStore.removeAll();
                                Ext.Msg.alert('提示', '无符合条件的通知已读会员！');
                            }

                            if (Mt.Notice.Store.mnoticeStore.getTotalCount() > Mt.Notice.Config.PageSize) {
                                Mt.Notice.View.Running.mnoticeGrid.bottomToolbar.show();
                            } else {
                                Mt.Notice.View.Running.mnoticeGrid.bottomToolbar.hide();
                            }
                            Mt.Notice.View.Running.noticeGrid.ownerCt.doLayout();
                        }
                    });
                }
            },
            /**
             * 反选
             */
            onReverseSelect: function() {
                for (var i = this.getView().getRows().length - 1; i >= 0; i--) {
                    if (this.sm.isSelected(i)) {
                        this.sm.deselectRow(i);
                    } else {
                        this.sm.selectRow(i, true);
                    }
                }
            },
            /**
             * 新建通知已读会员
             */
            addMnotice: function() {
                if (Mt.Notice.View.MnoticeView.edit_window == null) {
                    Mt.Notice.View.MnoticeView.edit_window = new Mt.Notice.View.MnoticeView.EditWindow();
                }
                Mt.Notice.View.MnoticeView.edit_window.resetBtn.setVisible(false);
                Mt.Notice.View.MnoticeView.edit_window.saveBtn.setText('保 存');
                Mt.Notice.View.MnoticeView.edit_window.setTitle('添加通知已读会员');
                Mt.Notice.View.MnoticeView.edit_window.savetype = 0;
                Mt.Notice.View.MnoticeView.edit_window.mtest_id.setValue("");
                Mt.Notice.View.MnoticeView.edit_window.show();
                Mt.Notice.View.MnoticeView.edit_window.maximize();
            },
            /**
             * 编辑通知已读会员时先获得选中的通知已读会员信息
             */
            updateMnotice: function() {
                if (Mt.Notice.View.MnoticeView.edit_window == null) {
                    Mt.Notice.View.MnoticeView.edit_window = new Mt.Notice.View.MnoticeView.EditWindow();
                }
                Mt.Notice.View.MnoticeView.edit_window.saveBtn.setText('修 改');
                Mt.Notice.View.MnoticeView.edit_window.resetBtn.setVisible(true);
                Mt.Notice.View.MnoticeView.edit_window.setTitle('修改通知已读会员');
                Mt.Notice.View.MnoticeView.edit_window.editForm.form.loadRecord(this.getSelectionModel().getSelected());
                Mt.Notice.View.MnoticeView.edit_window.savetype = 1;

                Mt.Notice.View.MnoticeView.edit_window.show();
                Mt.Notice.View.MnoticeView.edit_window.maximize();
            },
            /**
             * 删除通知已读会员
             */
            deleteMnotice: function() {
                Ext.Msg.confirm('提示', '确实要删除所选的通知已读会员吗?', this.confirmDeleteMnotice, this);
            },
            /**
             * 确认删除通知已读会员
             */
            confirmDeleteMnotice: function(btn) {
                if (btn == 'yes') {
                    var del_mtest_ids = "";
                    var selectedRows = this.getSelectionModel().getSelections();
                    for (var flag = 0; flag < selectedRows.length; flag++) {
                        del_mtest_ids = del_mtest_ids + selectedRows[flag].data.mtest_id + ",";
                    }
                    ExtServiceMnotice.deleteByIds(del_mtest_ids);
                    this.doSelectMnotice();
                    Ext.Msg.alert("提示", "删除成功！");
                }
            }
        })
    },
    /**
     * 窗口：批量上传通知
     */
    UploadWindow: Ext.extend(Ext.Window, {
        constructor: function(config) {
            config = Ext.apply({
                title: '批量上传通知数据', width: 400, height: 110, minWidth: 300, minHeight: 100,
                layout: 'fit', plain: true, bodyStyle: 'padding:5px;', buttonAlign: 'center', closeAction: "hide",
                items: [
                    new Ext.form.FormPanel({
                        ref: 'uploadForm', fileUpload: true,
                        width: 500, labelWidth: 50, autoHeight: true, baseCls: 'x-plain',
                        frame: true, bodyStyle: 'padding: 10px 10px 10px 10px;',
                        defaults: {
                            anchor: '95%', allowBlank: false, msgTarget: 'side'
                        },
                        items: [{
                                xtype: 'fileuploadfield',
                                fieldLabel: '文 件', name: 'upload_file', ref: 'upload_file',
                                emptyText: '请上传通知Excel文件', buttonText: '',
                                accept: 'application/vnd.ms-excel',
                                buttonCfg: {iconCls: 'upload-icon'}
                            }]
                    })
                ],
                buttons: [{
                        text: '上 传',
                        scope: this,
                        handler: function() {
                            uploadWindow = this;
                            validationExpression = /([\u4E00-\u9FA5]|\w)+(.xlsx|.XLSX|.xls|.XLS)$/;/**允许中文名*/
                            var isValidExcelFormat = new RegExp(validationExpression);
                            var result = isValidExcelFormat.test(this.uploadForm.upload_file.getValue());
                            if (!result) {
                                Ext.Msg.alert('提示', '请上传Excel文件，后缀名为xls或者xlsx！');
                                return;
                            }
                            if (this.uploadForm.getForm().isValid()) {
                                Ext.Msg.show({
                                    title: '请等待', msg: '文件正在上传中，请稍后...',
                                    animEl: 'loading', icon: Ext.Msg.WARNING,
                                    closable: true, progress: true, progressText: '', width: 300
                                });
                                this.uploadForm.getForm().submit({
                                    url: 'index.php?go=admin.upload.uploadNotice',
                                    success: function(form, response) {
                                        Ext.Msg.alert('成功', '上传成功');
                                        uploadWindow.hide();
                                        uploadWindow.uploadForm.upload_file.setValue('');
                                        Mt.Notice.View.Running.noticeGrid.doSelectNotice();
                                    },
                                    failure: function(form, response) {
                                        Ext.Msg.alert('错误', response.result.data);
                                    }
                                });
                            }
                        }
                    }, {
                        text: '取 消',
                        scope: this,
                        handler: function() {
                            this.uploadForm.upload_file.setValue('');
                            this.hide();
                        }
                    }]
            }, config);
            Mt.Notice.View.UploadWindow.superclass.constructor.call(this, config);
        }
    }),
    /**
     * 窗口：批量上传商品图片
     */
    BatchUploadImagesWindow: Ext.extend(Ext.Window, {
        constructor: function(config) {
            config = Ext.apply({
                width: 400, height: 180, minWidth: 300, minHeight: 100, closeAction: "hide",
                layout: 'fit', plain: true, bodyStYle: 'padding:5px;', buttonAlign: 'center',
                items: [
                    new Ext.form.FormPanel({
                        ref: 'uploadForm', fileUpload: true,
                        width: 500, labelWidth: 50, autoHeight: true, baseCls: 'x-plain',
                        frame: true, bodyStyle: 'padding: 10px 10px 10px 10px;',
                        defaults: {
                            anchor: '95%', allowBlank: false, msgTarget: 'side'
                        },
                        items: [{
                                xtype: 'fileuploadfield', fieldLabel: '文 件', ref: 'upload_file',
                                emptyText: '请批量上传更新时间文件(zip)', buttonText: '',
                                accept: 'application/zip,application/x-zip-compressed',
                                buttonCfg: {iconCls: 'upload-icon'}
                            },
                            {xtype: 'displayfield', value: '*.图片名不能重名<br/>*.压缩文件最大不要超过50M'}]
                    })
                ],
                buttons: [{
                        text: '上 传',
                        scope: this,
                        handler: function() {
                            uploadImagesWindow = this;
                            validationExpression = /([\u4E00-\u9FA5]|\w)+(.zip|.ZIP)$/;
                            var isValidExcelFormat = new RegExp(validationExpression);
                            var result = isValidExcelFormat.test(this.uploadForm.upload_file.getValue());
                            if (!result) {
                                Ext.Msg.alert('提示', '请上传ZIP文件，后缀名为zip！');
                                return;
                            }
                            var uploadImageUrl = 'index.php?go=admin.upload.uploadNoticefilepaths';

                            if (this.uploadForm.getForm().isValid()) {
                                Ext.Msg.show({
                                    title: '请等待', msg: '文件正在上传中，请稍后...',
                                    animEl: 'loading', icon: Ext.Msg.WARNING,
                                    closable: true, progress: true, progressText: '', width: 300
                                });
                                this.uploadForm.getForm().submit({
                                    url: uploadImageUrl,
                                    success: function(form, response) {
                                        Ext.Msg.alert('成功', '上传成功');
                                        uploadImagesWindow.hide();
                                        uploadImagesWindow.uploadForm.upload_file.setValue('');
                                        Mt.Notice.View.Running.noticeGrid.doSelectNotice();
                                    },
                                    failure: function(form, response) {
                                        if (response.result && response.result.data) {
                                            Ext.Msg.alert('错误', response.result.data);
                                        }
                                    }
                                });
                            }
                        }
                    }, {
                        text: '取 消',
                        scope: this,
                        handler: function() {
                            this.uploadForm.upload_file.setValue('');
                            this.hide();
                        }
                    }]
            }, config);
            Mt.Notice.View.BatchUploadImagesWindow.superclass.constructor.call(this, config);
        }
    }),
    /**
     * 视图：通知列表
     */
    Grid: Ext.extend(Ext.grid.GridPanel, {
        constructor: function(config) {
            config = Ext.apply({
                /**
                 * 查询条件
                 */
                filter: null,
                region: 'center',
                store: Mt.Notice.Store.noticeStore,
                sm: this.sm,
                frame: true, trackMouseOver: true, enableColumnMove: true, columnLines: true,
                loadMask: true, stripeRows: true, headerAsText: false,
                defaults: {
                    autoScroll: true
                },
                cm: new Ext.grid.ColumnModel({
                    defaults: {
                        width: 120, sortable: true
                    },
                    columns: [
                        this.sm,
                        {header: '标识', dataIndex: 'notice_id', hidden: true},
                        {header: '通知类型', dataIndex: 'ntypeShow'},
                        {header: '通知标题', dataIndex: 'notice_title'},
                        {header: '全部发送', dataIndex: 'toall', renderer: function(value) {
                                if (value == true) {
                                    return "是";
                                } else {
                                    return "否";
                                }
                            }},
                        {header: '发送人', dataIndex: 'admin_name'}
                    ]
                }),
                tbar: {
                    xtype: 'container', layout: 'anchor', height: 27 * 3, style: 'font-size:14px',
                    defaults: {
                        height: 27, anchor: '100%'
                    },
                    items: [
                        new Ext.Toolbar({
                            enableOverflow: true, width: 100,
                            defaults: {
                                xtype: 'textfield',
                                listeners: {
                                    specialkey: function(field, e) {
                                        if (e.getKey() == Ext.EventObject.ENTER)
                                            this.ownerCt.ownerCt.ownerCt.doSelectNotice();
                                    }
                                }
                            },
                            items: [
                                '通知类型', '&nbsp;&nbsp;', {ref: '../nntype', xtype: 'combo', mode: 'local',
                                    triggerAction: 'all', lazyRender: true, editable: false,
                                    store: Mt.Notice.Store.comNtypeStore,
                                    valueField: 'value', displayField: 'text'
                                }, '&nbsp;&nbsp;',
                                '通知标题', '&nbsp;&nbsp;', {ref: '../nnotice_title'}, '&nbsp;&nbsp;',
                                {
                                    xtype: 'button', text: '查询', scope: this,
                                    handler: function() {
                                        this.doSelectNotice();
                                    }
                                },
                                {
                                    xtype: 'button', text: '重置', scope: this,
                                    handler: function() {
                                        this.topToolbar.nntype.setValue("");
                                        this.topToolbar.nnotice_title.setValue("");
                                        this.filter = {};
                                        this.doSelectNotice();
                                    }
                                }]
                        }),
                        new Ext.Toolbar({
                            defaults: {scope: this},
                            items: [
                                {
                                    text: '添加通知', iconCls: 'icon-add',
                                    handler: function() {
                                        this.addNotice("1");
                                    }
                                }/*, '-',
                                {
                                    text: '添加新课程上线通知', iconCls: 'icon-add',
                                    handler: function() {
                                        this.addNotice("2");
                                    }
                                }, '-',
                                {
                                    text: '添加面授培训通知', iconCls: 'icon-add',
                                    handler: function() {
                                        this.addNotice("3");
                                    }
                                }, '-',
                                {
                                    text: '添加课程到期通知', iconCls: 'icon-add',
                                    handler: function() {
                                        this.addNotice("4");
                                    }
                                }, '-',
                                {
                                    text: '添加下载资料通知', iconCls: 'icon-add',
                                    handler: function() {
                                        this.addNotice("5");
                                    }
                                }*/
                            ]
                        }
                        ),
                        new Ext.Toolbar({
                            defaults: {scope: this},
                            items: [
                                {
                                    text: '反选', iconCls: 'icon-reverse',
                                    handler: function() {
                                        this.onReverseSelect();
                                    }
                                }, '-', {
                                    text: '修改通知', ref: '../../btnUpdate', iconCls: 'icon-edit', disabled: true,
                                    handler: function() {
                                        this.updateNotice();
                                    }
                                }, '-', {
                                    text: '删除通知', ref: '../../btnRemove', iconCls: 'icon-delete', disabled: true,
                                    handler: function() {
                                        this.deleteNotice();
                                    }
                                }, '-', {
                                    xtype: 'tbsplit', text: '导入', iconCls: 'icon-import',
                                    handler: function() {
                                        this.importNotice();
                                    },
                                    menu: {
                                        xtype: 'menu', plain: true,
                                        items: [
                                            {text: '批量导入通知', iconCls: 'icon-import', scope: this, handler: function() {
                                                    this.importNotice()
                                                }},
                                            {text: '批量导入文件', iconCls: 'icon-import', scope: this, handler: function() {
                                                    this.batchUploadImages("upload_filepath_files", "文件")
                                                }}
                                        ]}
                                }, '-', {
                                    text: '导出', iconCls: 'icon-export',
                                    handler: function() {
                                        this.exportNotice();
                                    }
                                }, '-', {
                                    xtype: 'tbsplit', text: '查看通知', ref: '../../tvpView', iconCls: 'icon-updown',
                                    enableToggle: true, disabled: true,
                                    handler: function() {
                                        this.showNotice()
                                    },
                                    menu: {
                                        xtype: 'menu', plain: true,
                                        items: [
                                            {text: '上方', group: 'mlayout', checked: false, iconCls: 'view-top', scope: this, handler: function() {
                                                    this.onUpDown(1)
                                                }},
                                            {text: '下方', group: 'mlayout', checked: true, iconCls: 'view-bottom', scope: this, handler: function() {
                                                    this.onUpDown(2)
                                                }},
                                            {text: '左侧', group: 'mlayout', checked: false, iconCls: 'view-left', scope: this, handler: function() {
                                                    this.onUpDown(3)
                                                }},
                                            {text: '右侧', group: 'mlayout', checked: false, iconCls: 'view-right', scope: this, handler: function() {
                                                    this.onUpDown(4)
                                                }},
                                            {text: '隐藏', group: 'mlayout', checked: false, iconCls: 'view-hide', scope: this, handler: function() {
                                                    this.hideNotice();
                                                    Mt.Notice.Config.View.IsShow = 0;
                                                }}, '-',
                                            {text: '固定', ref: 'mBind', checked: true, scope: this, checkHandler: function(item, checked) {
                                                    this.onBindGrid(item, checked);
                                                    Mt.Notice.Cookie.set('View.IsFix', Mt.Notice.Config.View.IsFix);
                                                }}
                                        ]}
                                }, '-', {
                                    text: '选择会员', ref: '../../tmember', iconCls: 'icon-edit', disabled: true,
                                    handler: function() {
                                        if (Mt.Notice.View.Running.selectMemberWindow == null || Mt.Notice.View.Running.selectMemberWindow.hidden) {
                                            this.showMember();
                                        } else {
                                            this.hideMember();
                                        }
                                    }
                                }, '-']}
                        )]
                },
                bbar: new Ext.PagingToolbar({
                    pageSize: Mt.Notice.Config.PageSize,
                    store: Mt.Notice.Store.noticeStore,
                    scope: this, autoShow: true, displayInfo: true,
                    displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',
                    emptyMsg: "无显示数据",
                    listeners: {
                        change: function(thisbar, pagedata) {
                            if (Mt.Notice.Viewport) {
                                if (Mt.Notice.Config.View.IsShow == 1) {
                                    Mt.Notice.View.IsSelectView = 1;
                                }
                                this.ownerCt.hideNotice();
                                Mt.Notice.Config.View.IsShow = 0;
                            }
                        }
                    },
                    items: [
                        {xtype: 'label', text: '每页显示'},
                        {xtype: 'numberfield', value: Mt.Notice.Config.PageSize, minValue: 1, width: 35,
                            style: 'text-align:center', allowBlank: false,
                            listeners:
                                    {
                                        change: function(Field, newValue, oldValue) {
                                            var num = parseInt(newValue);
                                            if (isNaN(num) || !num || num < 1)
                                            {
                                                num = Mt.Notice.Config.PageSize;
                                                Field.setValue(num);
                                            }
                                            this.ownerCt.pageSize = num;
                                            Mt.Notice.Config.PageSize = num;
                                            this.ownerCt.ownerCt.doSelectNotice();
                                        },
                                        specialKey: function(field, e) {
                                            if (e.getKey() == Ext.EventObject.ENTER) {
                                                var num = parseInt(field.getValue());
                                                if (isNaN(num) || !num || num < 1)
                                                {
                                                    num = Mt.Notice.Config.PageSize;
                                                }
                                                this.ownerCt.pageSize = num;
                                                Mt.Notice.Config.PageSize = num;
                                                this.ownerCt.ownerCt.doSelectNotice();
                                            }
                                        }
                                    }
                        },
                        {xtype: 'label', text: '个'}
                    ]
                })
            }, config);
            //初始化显示通知列表
            this.doSelectNotice();
            Mt.Notice.View.Grid.superclass.constructor.call(this, config);
            //创建在Grid里显示的通知信息Tab页
            Mt.Notice.View.Running.viewTabs = new Mt.Notice.View.NoticeView.Tabs();
            this.addListener('rowdblclick', this.onRowDoubleClick);
        },
        /**
         * 行选择器
         */
        sm: new Ext.grid.CheckboxSelectionModel({
            //handleMouseDown : Ext.emptyFn,
            listeners: {
                selectionchange: function(sm) {
                    // 判断删除和更新按钮是否可以激活
                    this.grid.btnRemove.setDisabled(sm.getCount() < 1);
                    this.grid.btnUpdate.setDisabled(sm.getCount() != 1);
                    this.grid.tvpView.setDisabled(sm.getCount() != 1);
                    this.grid.tmember.setDisabled(sm.getCount() != 1);
                },
                rowselect: function(sm, rowIndex, record) {
                    if (sm.getCount() != 1) {
                        this.grid.hideNotice();
                        Mt.Notice.Config.View.IsShow = 0;
                        this.grid.hideMember();
                    } else {
                        if (Mt.Notice.View.IsSelectView == 1) {
                            Mt.Notice.View.IsSelectView = 0;
                            this.grid.showNotice();
                        }
                    }
                },
                rowdeselect: function(sm, rowIndex, record) {
                    if (sm.getCount() != 1) {
                        if (Mt.Notice.Config.View.IsShow == 1) {
                            Mt.Notice.View.IsSelectView = 1;
                        }
                        this.grid.hideNotice();
                        Mt.Notice.Config.View.IsShow = 0;
                    }
                }
            }
        }),
        /**
         * 双击选行
         */
        onRowDoubleClick: function(grid, rowIndex, e) {
            if (!Mt.Notice.Config.View.IsShow) {
                this.sm.selectRow(rowIndex);
                this.showNotice();
                this.tvpView.toggle(true);
            } else {
                this.hideNotice();
                Mt.Notice.Config.View.IsShow = 0;
                this.sm.deselectRow(rowIndex);
                this.tvpView.toggle(false);
            }
        },
        /**
         * 是否绑定在本窗口上
         */
        onBindGrid: function(item, checked) {
            if (checked) {
                Mt.Notice.Config.View.IsFix = 1;
            } else {
                Mt.Notice.Config.View.IsFix = 0;
            }
            if (this.getSelectionModel().getSelected() == null) {
                Mt.Notice.Config.View.IsShow = 0;
                return;
            }
            if (Mt.Notice.Config.View.IsShow == 1) {
                this.hideNotice();
                Mt.Notice.Config.View.IsShow = 0;
            }
            this.showNotice();
        },
        /**
         * 反选
         */
        onReverseSelect: function() {
            for (var i = this.getView().getRows().length - 1; i >= 0; i--) {
                if (this.sm.isSelected(i)) {
                    this.sm.deselectRow(i);
                } else {
                    this.sm.selectRow(i, true);
                }
            }
        },
        /**
         * 查询符合条件的通知
         */
        doSelectNotice: function() {
            if (this.topToolbar) {
                var nntype = this.topToolbar.nntype.getValue();
                var nnotice_title = this.topToolbar.nnotice_title.getValue();
                this.filter = {'ntype': nntype, 'notice_title': nnotice_title};
            }
            var condition = {'start': 0, 'limit': Mt.Notice.Config.PageSize};
            Ext.apply(condition, this.filter);
            ExtServiceNotice.queryPageNotice(condition, function(provider, response) {
                if (response.result && response.result.data) {
                    var result = new Array();
                    result['data'] = response.result.data;
                    result['totalCount'] = response.result.totalCount;
                    Mt.Notice.Store.noticeStore.loadData(result);
                } else {
                    Mt.Notice.Store.noticeStore.removeAll();
                    Ext.Msg.alert('提示', '无符合条件的通知！');
                }
            });
        },
        /**
         * 显示通知视图
         * 显示通知的视图相对通知列表Grid的位置
         * 1:上方,2:下方,0:隐藏。
         */
        onUpDown: function(viewDirection) {
            Mt.Notice.Config.View.Direction = viewDirection;
            switch (viewDirection) {
                case 1:
                    this.ownerCt.north.add(Mt.Notice.View.Running.viewTabs);
                    break;
                case 2:
                    this.ownerCt.south.add(Mt.Notice.View.Running.viewTabs);
                    break;
                case 3:
                    this.ownerCt.west.add(Mt.Notice.View.Running.viewTabs);
                    break;
                case 4:
                    this.ownerCt.east.add(Mt.Notice.View.Running.viewTabs);
                    break;
            }
            Mt.Notice.Cookie.set('View.Direction', Mt.Notice.Config.View.Direction);
            if (this.getSelectionModel().getSelected() != null) {
                if ((Mt.Notice.Config.View.IsFix == 0) && (Mt.Notice.Config.View.IsShow == 1)) {
                    this.showNotice();
                }
                Mt.Notice.Config.View.IsFix = 1;
                Mt.Notice.View.Running.noticeGrid.tvpView.menu.mBind.setChecked(true, true);
                Mt.Notice.Config.View.IsShow = 0;
                this.showNotice();
            }
        },
        /**
         * 显示通知
         */
        showNotice: function() {
            if (this.getSelectionModel().getSelected() == null) {
                Ext.Msg.alert('提示', '请先选择通知！');
                Mt.Notice.Config.View.IsShow = 0;
                this.tvpView.toggle(false);
                return;
            }
            if (Mt.Notice.Config.View.IsFix == 0) {
                if (Mt.Notice.View.Running.view_window == null) {
                    Mt.Notice.View.Running.view_window = new Mt.Notice.View.NoticeView.Window();
                }
                if (Mt.Notice.View.Running.view_window.hidden) {
                    Mt.Notice.View.Running.view_window.show();
                    Mt.Notice.View.Running.view_window.winTabs.hideTabStripItem(Mt.Notice.View.Running.view_window.winTabs.tabFix);
                    this.updateViewNotice();
                    this.tvpView.toggle(true);
                    Mt.Notice.Config.View.IsShow = 1;
                } else {
                    this.hideNotice();
                    Mt.Notice.Config.View.IsShow = 0;
                }
                return;
            }
            switch (Mt.Notice.Config.View.Direction) {
                case 1:
                    if (!this.ownerCt.north.items.contains(Mt.Notice.View.Running.viewTabs)) {
                        this.ownerCt.north.add(Mt.Notice.View.Running.viewTabs);
                    }
                    break;
                case 2:
                    if (!this.ownerCt.south.items.contains(Mt.Notice.View.Running.viewTabs)) {
                        this.ownerCt.south.add(Mt.Notice.View.Running.viewTabs);
                    }
                    break;
                case 3:
                    if (!this.ownerCt.west.items.contains(Mt.Notice.View.Running.viewTabs)) {
                        this.ownerCt.west.add(Mt.Notice.View.Running.viewTabs);
                    }
                    break;
                case 4:
                    if (!this.ownerCt.east.items.contains(Mt.Notice.View.Running.viewTabs)) {
                        this.ownerCt.east.add(Mt.Notice.View.Running.viewTabs);
                    }
                    break;
            }
            this.hideNotice();
            if (Mt.Notice.Config.View.IsShow == 0) {
                Mt.Notice.View.Running.viewTabs.enableCollapse();
                switch (Mt.Notice.Config.View.Direction) {
                    case 1:
                        this.ownerCt.north.show();
                        break;
                    case 2:
                        this.ownerCt.south.show();
                        break;
                    case 3:
                        this.ownerCt.west.show();
                        break;
                    case 4:
                        this.ownerCt.east.show();
                        break;
                }
                this.updateViewNotice();
                this.tvpView.toggle(true);
                Mt.Notice.Config.View.IsShow = 1;
            } else {
                Mt.Notice.Config.View.IsShow = 0;
            }
            this.ownerCt.doLayout();
        },
        /**
         * 隐藏通知
         */
        hideNotice: function() {
            this.ownerCt.north.hide();
            this.ownerCt.south.hide();
            this.ownerCt.west.hide();
            this.ownerCt.east.hide();
            if (Mt.Notice.View.Running.view_window != null) {
                Mt.Notice.View.Running.view_window.hide();
            }
            this.tvpView.toggle(false);
            this.ownerCt.doLayout();
        },
        /**
         * 更新当前通知显示信息
         */
        updateViewNotice: function() {
            Mt.Notice.View.Running.mnoticeGrid.doSelectMnotice();
            if (Mt.Notice.View.Running.view_window != null) {
                Mt.Notice.View.Running.view_window.winTabs.tabNoticeDetail.update(this.getSelectionModel().getSelected().data);
            }
            Mt.Notice.View.Running.viewTabs.tabNoticeDetail.update(this.getSelectionModel().getSelected().data);
        },
        //更改通知类，型切换字段
        changeNtype: function(ntype) {
            var ntypes = ["1", "2", "3", "4", "5"];
            var visibles = [[false, false], [true, false], [false, false], [true, false], [false, true]];
            var visible = visibles[ntypes.indexOf(ntype)];
            Mt.Notice.View.Running.edit_window.lesson_name.setVisible(visible[0]);
            Mt.Notice.View.Running.edit_window.filepathUpload.setVisible(visible[1]);
            Mt.Notice.View.Running.edit_window.lesson_id.disabled = !visible[0];
            Mt.Notice.View.Running.edit_window.filepathUpload.disabled = !visible[1];
        },
        /**
         * 新建通知
         */
        addNotice: function(ntype) {
            if (Mt.Notice.View.Running.edit_window == null) {
                Mt.Notice.View.Running.edit_window = new Mt.Notice.View.EditWindow();
            }
            Mt.Notice.View.Running.edit_window.resetBtn.setVisible(false);
            Mt.Notice.View.Running.edit_window.saveBtn.setText('保 存');
            Mt.Notice.View.Running.edit_window.setTitle('添加通知');
            Mt.Notice.View.Running.edit_window.savetype = 0;
            Mt.Notice.View.Running.edit_window.notice_id.setValue("");
            Mt.Notice.View.Running.edit_window.filepathUpload.setValue("");
            Mt.Notice.View.Running.edit_window.filepathUpload.setVisible(true);

            this.changeNtype(ntype);
            Mt.Notice.View.Running.edit_window.ntype.setValue(ntype);

            switch (Mt.Notice.Config.OnlineEditor)
            {
                case 1:
                    if (CKEDITOR.instances.content)
                        CKEDITOR.instances.content.setData("");
                    break
                case 2:
                    if (Mt.Notice.View.EditWindow.KindEditor_content)
                        Mt.Notice.View.EditWindow.KindEditor_content.html("");
                    break
                case 3:
                    break
                default:
                    if (ue_content)
                        ue_content.setContent("");
            }

            Mt.Notice.View.Running.edit_window.show();
            Mt.Notice.View.Running.edit_window.maximize();
        },
        /**
         * 编辑通知时先获得选中的通知信息
         */
        updateNotice: function() {
            if (Mt.Notice.View.Running.edit_window == null) {
                Mt.Notice.View.Running.edit_window = new Mt.Notice.View.EditWindow();
            }
            Mt.Notice.View.Running.edit_window.saveBtn.setText('修 改');
            Mt.Notice.View.Running.edit_window.resetBtn.setVisible(true);
            Mt.Notice.View.Running.edit_window.setTitle('修改通知');
            Mt.Notice.View.Running.edit_window.editForm.form.loadRecord(this.getSelectionModel().getSelected());
            Mt.Notice.View.Running.edit_window.savetype = 1;
            Mt.Notice.View.Running.edit_window.filepathUpload.setValue(Mt.Notice.View.Running.edit_window.filename.getValue());
            var ntype = this.getSelectionModel().getSelected().data.ntype;
            this.changeNtype(ntype);
            switch (Mt.Notice.Config.OnlineEditor)
            {
                case 1:
                    if (CKEDITOR.instances.content)
                        CKEDITOR.instances.content.setData(this.getSelectionModel().getSelected().data.content);
                    break
                case 2:
                    if (Mt.Notice.View.EditWindow.KindEditor_content)
                        Mt.Notice.View.EditWindow.KindEditor_content.html(this.getSelectionModel().getSelected().data.content);
                    break
                case 3:
                    if (xhEditor_content)
                        xhEditor_content.setSource(this.getSelectionModel().getSelected().data.content);
                    break
                default:
                    if (ue_content)
                        ue_content.setContent(this.getSelectionModel().getSelected().data.content);
            }

            Mt.Notice.View.Running.edit_window.show();
            Mt.Notice.View.Running.edit_window.maximize();
        },
        /**
         * 删除通知
         */
        deleteNotice: function() {
            Ext.Msg.confirm('提示', '确实要删除所选的通知吗?', this.confirmDeleteNotice, this);
        },
        /**
         * 确认删除通知
         */
        confirmDeleteNotice: function(btn) {
            if (btn == 'yes') {
                var del_notice_ids = "";
                var selectedRows = this.getSelectionModel().getSelections();
                for (var flag = 0; flag < selectedRows.length; flag++) {
                    del_notice_ids = del_notice_ids + selectedRows[flag].data.notice_id + ",";
                }
                ExtServiceNotice.deleteByIds(del_notice_ids);
                this.doSelectNotice();
                Ext.Msg.alert("提示", "删除成功！");
            }
        },
        /**
         * 显示会员
         */
        showMember: function() {
            if (Mt.Notice.View.Running.selectMemberWindow == null) {
                Mt.Notice.View.Running.selectMemberWindow = new Mt.Notice.View.MemberView.SelectMemberWindow();
            }
            var notice_id = Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected().data.notice_id;

            //关联会员ID组成的字符串
            var memberStr = Mt.Notice.View.Running.noticeGrid.getSelectionModel().getSelected().data.memberStr;
            var selData = {};
            var oldData = {};
            if (memberStr) {
                var memberArr = memberStr.split(",");
                for (var i = 0; i < memberArr.length; i++) {
                    selData[memberArr[i]] = true;//ture为已存在的关联货品
                    oldData[memberArr[i]] = {};
                    oldData[memberArr[i]].active = true;
                }
            }
            var selMemberWin = Mt.Notice.View.Running.selectMemberWindow;
            var selMemberGrid = selMemberWin.memberGrid;
            selMemberWin.selData = selData;
            selMemberWin.oldData = oldData;
            selMemberWin.changeTitle();//根据选择的货品,修改标题

            selMemberGrid.notice_id = notice_id;
            if (selMemberWin.hidden) {
                Mt.Notice.View.Running.selectMemberWindow.memberGrid.topToolbar.area_id.setValue("");
                Mt.Notice.View.Running.selectMemberWindow.memberGrid.topToolbar.mdepartment_id.setValue("");
                Mt.Notice.View.Running.selectMemberWindow.memberGrid.topToolbar.mposition_id.setValue("");
                Mt.Notice.View.Running.selectMemberWindow.memberGrid.topToolbar.musername.setValue("");
                selMemberGrid.filter = {selMember: memberStr};
                selMemberGrid.topToolbar.menus.all.setChecked(true);
                selMemberGrid.isSelect.toggle(false);
                Mt.Notice.Store.selectMemberStore.removeAll();
            }
            selMemberGrid.doSelectMember();
            selMemberWin.show();
        },
        /**
         * 隐藏会员
         */
        hideMember: function() {
            if (Mt.Notice.View.Running.selectMemberWindow != null) {
                Mt.Notice.View.Running.selectMemberWindow.hide();
            }
        },
        /**
         * 导出通知
         */
        exportNotice: function() {
            ExtServiceNotice.exportNotice(this.filter, function(provider, response) {
                if (response.result.data) {
                    window.open(response.result.data);
                }
            });
        },
        /**
         * 导入通知
         */
        importNotice: function() {
            if (Mt.Notice.View.current_uploadWindow == null) {
                Mt.Notice.View.current_uploadWindow = new Mt.Notice.View.UploadWindow();
            }
            Mt.Notice.View.current_uploadWindow.show();
        },
        /**
         * 批量上传商品图片
         */
        batchUploadImages: function(inputname, title) {
            if (Mt.Notice.View.Running.batchUploadImagesWindow == null) {
                Mt.Notice.View.Running.batchUploadImagesWindow = new Mt.Notice.View.BatchUploadImagesWindow();
            }

            Mt.Notice.View.Running.batchUploadImagesWindow.setTitle("批量上传" + title);
            Mt.Notice.View.Running.batchUploadImagesWindow.uploadForm.upload_file.name = inputname;
            Mt.Notice.View.Running.batchUploadImagesWindow.show();
        }
    }),
    /**
     * 核心内容区
     */
    Panel: Ext.extend(Ext.form.FormPanel, {
        constructor: function(config) {
            Mt.Notice.View.Running.noticeGrid = new Mt.Notice.View.Grid();
            if (Mt.Notice.Config.View.IsFix == 0) {
                Mt.Notice.View.Running.noticeGrid.tvpView.menu.mBind.setChecked(false, true);
            }
            config = Ext.apply({
                region: 'center', layout: 'fit', frame: true,
                items: {
                    layout: 'border',
                    items: [
                        Mt.Notice.View.Running.noticeGrid,
                        {region: 'north', ref: 'north', layout: 'fit', collapseMode: 'mini', border: false, split: true, hidden: true},
                        {region: 'south', ref: 'south', layout: 'fit', collapseMode: 'mini', border: false, split: true, hidden: true, items: [Mt.Notice.View.Running.viewTabs]},
                        {region: 'west', ref: 'west', layout: 'fit', collapseMode: 'mini', border: false, split: true, hidden: true},
                        {region: 'east', ref: 'east', layout: 'fit', collapseMode: 'mini', border: false, split: true, hidden: true}
                    ]
                }
            }, config);
            Mt.Notice.View.Panel.superclass.constructor.call(this, config);
        }
    }),
    /**
     * 当前运行的可视化对象
     */
    Running: {
        /**
         * 当前通知Grid对象
         */
        noticeGrid: null,
        /**
         * 推荐会员
         */
        selectMemberWindow: null,
        /**
         * 显示通知信息及关联信息列表的Tab页
         */
        /**
         * 当前会员阅读通知Grid对象
         */
        mnoticeGrid: null,
        viewTabs: null,
        /**
         * 当前创建的编辑窗口
         */
        edit_window: null,
        /**
         * 当前的显示窗口
         */
        view_window: null
    }
};
/**
 * Controller:主程序
 */
Ext.onReady(function() {
    Ext.QuickTips.init();
    Ext.state.Manager.setProvider(Mt.Notice.Cookie);
    Ext.Direct.addProvider(Ext.app.REMOTING_API);
    Mt.Notice.Init();
    /**
     * 通知数据模型获取数据Direct调用
     */
    Mt.Notice.Store.noticeStore.proxy = new Ext.data.DirectProxy({
        api: {read: ExtServiceNotice.queryPageNotice}
    });
    /**
     * 通知页面布局
     */
    Mt.Notice.Viewport = new Ext.Viewport({
        layout: 'border',
        items: [new Mt.Notice.View.Panel()]
    });
    Mt.Notice.Viewport.doLayout();
    setTimeout(function() {
        Ext.get('loading').remove();
        Ext.get('loading-mask').fadeOut({
            remove: true
        });
    }, 250);
});